$(function(){
	function tip(){
		this.config=tip._default;//规格
		this.templates=tip._templates;//材料
		this.addStyle(this.templates.css);
	}
	tip.prototype={
		//内配一个重新的规格的内存空间
		mergeObject:function(_obj){
			var obj={};
            for(var i in this.config){
                obj[i]=_obj[i]||this.config[i];  
            }
			return obj;
        },
		//加载材料，初始化材料
		initMaterial:function(){
			//把材料放在身边
			this.top=$(this.templates.root);
			//装载材料完毕
			var close=this.top.find(".close").hide();
				content=this.top.find(".content");
				_this=this;
			content.html(_this.config.content);
			close.bind("click",function(){
				_this.config.konwe;
			})
			$("body").append(this.top);
		},
		close:function(){
			this.top.hide()
		},
		show:function(obj){
			this.initPos(obj);
			this.top.show();
		},
		addStyle:function(content){
			var style;
			if(document.all) {//IE
				style =document.createStyleSheet();
				style.cssText = content;
			}
			else{
				style =document.createElement("style");
				style.type ="text/css";
				//style.innerHTML = content;//Safari、Chrome下innerHTML只读
				style.textContent = content;
			}
			try{document.getElementsByTagName("head")[0].appendChild(style);}catch(e){}
		},
		initPos:function(obj){
			//造成的样
			var direction=this.config.direction,
				offset=this.top.find(".showposition"),
				pos=[];
				posA=this.calcElem(obj);
				posH=this.top.height();
				posW=this.top.width();
				
				setP=this.config.offset;
			switch(direction){
				case "up":
					pos.push("diretionvertiacl","bottom");
					offset.css({left:this.config.flg});
					this.top.css({left:posA[0]+setP[0]+"px",top:posA[1]-posH-6+setP[1]+"px"});
				break;
				case "right":
					pos.push("diretionlevel","left");
					offset.css({top:this.config.flg});
					this.top.css({left:posA[0]+posW+6+setP[0]+"px",top:posA[1]+setP[1]+"px"});
				break;
				case "down":
					pos.push("diretionvertiacl","top");
					offset.css({left:this.config.flg});
					this.top.css({left:posA[0]+setP[0]+"px",top:posA[1]+posA[2]+setP[1]+6+"px"});
				break;
				case "left":
					pos.push("diretionlevel","right");
					offset.css({top:this.config.flg});
					this.top.css({left:posA[0]-posW-6+setP[0]+"px",top:posA[1]+setP[1]+"px"});
				break;

			}
			this.top.find(".showposition").addClass(pos.join(" "));
		},
		calcElem:function(obj){
			return [obj.offset().left,obj.offset().top,obj.height(),obj.width()];
		}
	};
	
	//材料
	tip._templates={
		"root":'<div id="wrap_level">'
+			'<div class="wrap_tip new_funtion_tip">'
+ 			'<i class="init lefttop"></i>'
+			'<i class="init righttop"></i>'
+			'<i class="init bottomleft"></i>'
+			'<i class="init bottomright"></i>'
+			'<i class="init close"></i>'
+			'<i class="showposition" style="display:block;"></i>'
+			'<div class="content">#content#</div>'
+			'<a href="#" class="close"></a>'
+			'</div></div>',
		"css":
'#wrap_level{position:absolute;left:0px; top:290px; display:none;}'
+'#wrap_level .wrap_tip{position:relative;background-color:#FFFFE5;border: 1px solid #CCC; font-size:12px; width:120px;}'
+'#wrap_level .wrap_tip i{width:2px; height:2px;position:absolute;background: url(http://s.liepin.com/images/v8/plugins/supertitle/title_bg.png) no-repeat;}'
+'#wrap_level .wrap_tip i.lefttop{left:-1px;top:-1px;background-position: 0px 0px;}'
+'#wrap_level .wrap_tip i.righttop{right: -1px;top: -1px;background-position: -2px 0px;}'
+'#wrap_level .wrap_tip i.bottomleft{left: -1px;bottom:-1px;background-position: 0px -2px;}'
+'#wrap_level .wrap_tip i.bottomright{right: -1px;bottom:-1px;background-position: -2px -2px;}'
+'#wrap_level .wrap_tip i.init{background-color:#fff;overflow:hidden;}'
+'#wrap_level .wrap_tip i.close{background-color:#fff;overflow:hidden;background-position: -14px -8px; height:7px; width:8px; right:3px; top:4px;}'
+'#wrap_level .wrap_tip i.diretionlevel{width:6px;height:9px; top:6px; overflow:hidden;}'
+'#wrap_level .wrap_tip i.diretionvertiacl{width:9px;height:6px; left:6px; overflow:hidden;}'
+'#wrap_level .wrap_tip i.right{right:-6px;background-position: -7px -7px;}'
+'#wrap_level .wrap_tip i.left{left:-6px;background-position: 0px -7px;}'
+'#wrap_level .wrap_tip i.top{top:-6px;background-position: -5px 0px;}'
+'#wrap_level .wrap_tip i.bottom{bottom:-6px;background-position: -15px 0px;}'
+'#wrap_level .wrap_tip div.content{padding:5px 5px 5px 5px; line-height:14px; text-indent:2em}'
+'#wrap_level .wrap_tip a.close{line-height:15px; height:14px;}'

	};
	//规格
	tip._default={
		"direction":"up",//up right down down
		"offset":[0,0], //left top
		"flg":"6px",
		"konwe":null, //我知道的事件
		"inite":null,  //加载事件
		"openall":false, //支持多开
		"isclose":false,
		"content":""
	};
	(function(fyx){
		fyx.fn.showtip=function(obj){
			var	_obj=new tip,
				root=_obj.templates.root;
			_obj.config=_obj.mergeObject(obj);
			_obj.initMaterial();//创建物体
			this.each(function(index){
				var _this=$(this);
				_this.bind("mouseover",function(){_obj.show(_this)});
				if(_obj.config.isclose){
					_this.bind("mouseout",function(){_obj.close()});
				}
		
			})
		}
	})(jQuery);
});